package com.bestom.bestoma10demo;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Handler;

/**
 * @author bestom
 * Monitoring alarm clock
 */
public class AlarmReceiver extends BroadcastReceiver{

    private Ringtone mRingTone;
    @Override
    public void onReceive(Context context, Intent intent) {

        Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
        mRingTone = RingtoneManager.getRingtone(context, notification);
        if (mRingTone != null && !mRingTone.isPlaying()) {
            mRingTone.play();
        }

        Intent intent1 = new Intent("up_view");
        intent1.putExtra("up_view", "The alarm goes off. It will shut off automatically after 9 seconds");
        context.sendBroadcast(intent1);

        new Handler().postDelayed(() -> {
            if (mRingTone != null && mRingTone.isPlaying()) {
                mRingTone.stop();
            }
        },9000);
    }
}
